package com.example.administrator.hospitalmap;

import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import com.example.administrator.hospitalmap.R;

public class MainActivity extends AppCompatActivity {
    ImageView vwSearchHospital;
    ImageView vwAbout;
    ImageView vwShare;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Intent mapIntent = new Intent(this, MapActivity.class);
        final Intent aboutIntent = new Intent(this,AboutActivity.class);


        ActionBar actionBar = getSupportActionBar();
        if(actionBar!=null){
            actionBar.hide();
        }

        vwSearchHospital = findViewById(R.id.vw_ic_search_hospital);
        vwAbout = findViewById(R.id.vw_ic_about);
        vwShare = findViewById(R.id.vw_ic_share);

        vwSearchHospital.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(mapIntent);
            }
        });

        vwAbout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(aboutIntent);
            }
        });

        vwShare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareApp();
            }
        });

    }
    protected void shareApp() {
        try {
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_subject));
            shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_body));
            shareIntent.setType("text/plain");
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            String chooserTitle = getResources().getString(R.string.share_title);
            startActivity(Intent.createChooser(shareIntent, chooserTitle));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
